/* eslint-disable prettier/prettier */

// import fetch from "node-fetch";
// import { generate } from "openapi-typescript-codegen";

// (async () => {
//   try {

//     await generate({
//       input: "http://localhost:8101/api/question/v2/api-docs?group=default",
//       output: "./generatedQue",
//     });
//   } catch (error) {
//     console.error(error);
//   }
// })();
/* eslint-disable prettier/prettier */

import fetch from "node-fetch";
import { generate } from "openapi-typescript-codegen";

(async () => {
  try {
    // 先获取 OpenAPI 文档内容
    const response = await fetch("http://localhost:8101/api/question/v2/api-docs?group=default");
    let openApiSpec = await response.json();

    // 预处理文档：将 "Integer" 全部替换为 "integer"
    let openApiSpecStr = JSON.stringify(openApiSpec);
    openApiSpecStr = openApiSpecStr.replace(/"Integer"/g, '"integer"');
    openApiSpec = JSON.parse(openApiSpecStr);

    // 使用预处理后的文档生成代码
    await generate({
      input: openApiSpec, // 直接传入对象
      output: "./generatedQue",
    });
  } catch (error) {
    console.error(error);
  }
})();